home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / P_ROBO31.ZIP / WIMP.PR < prev   
Text File  |  1993-02-10  |  5KB  |  128 lines

  1. (**************************************************************************)
  2. (*                             W A R N I N G                              *)
  3. (*                                                                        *)
  4. (*  This Robot has NOT been designed to take advantage of the advanced    *)
  5. (*  features of P-ROBOTS, such as, Shields, Fuel, Teams or Obstructions.  *)
  6. (**************************************************************************)
  7.  
  8.   PROCEDURE Wimp;
  9.  
  10. {   Based on C-Robot "Hunter-Killer"
  11.  
  12.     Original by John Hardin
  13.  
  14.     strategy: Move at medium speed in the direction of the last detected
  15.               robot while scanning 360 degrees quickly. If a robot is
  16.               detected, charge at it at high speed, firing when in range.
  17.               If hit while scanning, run to a random location and resume.
  18.               Don't worry about running into a wall or another robot, since
  19.               that only causes 2% damage.  }
  20.  
  21.     { Wimp "globals" }
  22.   VAR
  23.     d              : Integer; { last damage check }
  24.     dir            : Integer; { direction looking & firing }
  25.     Range          : Integer;
  26.  
  27.  
  28.     PROCEDURE go(dest_x, dest_y : Integer);
  29.       { go to the point specified }
  30.     VAR
  31.       course         : Integer;
  32.     BEGIN
  33.       course := Angle_To(dest_x, dest_y);
  34.       drive(course, 100); { full speed ahead! }
  35.       WHILE (distance(loc_x, loc_y, dest_x, dest_y) > 100) AND (speed > 0)
  36.       DO {nothing} ;
  37.     END;
  38.  
  39.  
  40.     PROCEDURE run;
  41.       { RUN AWAY!! }
  42.     BEGIN 
  43.       go(50+Random(900), 50+Random(900));
  44.     END; { end of run }
  45.  
  46.  
  47.     PROCEDURE Sweep;
  48.       { sweepscan arena for target }
  49.     VAR
  50.       Range          : Integer;
  51.       return         : Boolean;
  52.     BEGIN
  53.       return := False;
  54.       drive(dir, 40); { drive at medium spped towards last target }
  55.       dir := dir DIV 10; { scan only even 10-degree slices }
  56.       dir := dir*10;
  57.       WHILE NOT return DO { scan until we see another robot }
  58.         BEGIN 
  59.           d := damage; { save current level of damage }
  60.           WHILE (damage = d) DO { scan until we take a hit }
  61.             BEGIN 
  62.               dir := dir+10; { increment scan direction }
  63.               dir := dir MOD 360; { MOD 360 }
  64.               Range := scan(dir, 10); { wide-range scan }
  65.               IF (Range > 0) THEN
  66.                 BEGIN
  67.                   return := True; { GOT ONE! }
  68.                   d := -10;
  69.                 END;
  70.             END; { continue scanning }
  71.           IF NOT return THEN run; { Ouch! let's get out of here! }
  72.         END; 
  73.     END; { end of sweep }
  74.  
  75.  
  76.     FUNCTION attack(direc : Integer) : Integer;
  77.       { attack robot at direc }
  78.     VAR
  79.       gotone         : Integer; { got robot flag }
  80.     BEGIN
  81.       gotone := 0; { don't got one }
  82.       dir := direc; { look in direc }
  83.       Range := scan(dir, 3); { narrow resolution }
  84.       WHILE (Range > 0) DO { keep attacking while he's there }
  85.         BEGIN 
  86.           IF (Range > 150) THEN drive(dir, 100) { charge! }
  87.           ELSE drive(dir+180, 100); { we're too close - back up! }
  88.           IF (Range > 40) THEN cannon(dir+3, Range); { fire! }
  89.           Range := scan(dir, 3); { check target again }
  90.           gotone := 1; { flag that we've a target }
  91.         END; 
  92.       IF (gotone = 0) THEN drive(dir, 50); { if we've lost him, trundle along }
  93.       attack := gotone; { towards where we last saw him }
  94.     END; { end of attack }
  95.  
  96.  
  97.     PROCEDURE target;
  98.       { search for and attack target }
  99.     VAR
  100.       startdir       : Integer; { direction robot originally seen at }
  101.       curdir         : Integer; { direction we're currently looking }
  102.     BEGIN
  103.       d := damage; { save current damage }
  104.       startdir := dir; { save original direction }
  105.       curdir := dir-5; { back up 5 degrees }
  106.       WHILE (curdir < startdir+7) AND (d = damage) DO
  107.         { until we've looked through ten degrees }
  108.         IF (attack(curdir) > 0) THEN { is somebody there? }
  109.           BEGIN 
  110.             startdir := dir; { yes - Blast him! }
  111.             curdir := startdir-6; { back up the scanner again so we don't }
  112.           END; { lose him and keep looking }
  113.       curdir := curdir+2; { increment scan direction }
  114.     END; { start scanning again }
  115.  
  116.  
  117.   BEGIN {Wimp main}
  118.     d := damage; { get starting damage }
  119.     dir := 0; { starting scan direction }
  120.     run;
  121.     WHILE True DO { loop is executed forever }
  122.       BEGIN 
  123.         Sweep; { sweep arena at high speed }
  124.         target; { acquire and attack detected robot }
  125.       END; 
  126.   END; { end of Wimp main }
  127.  
  128.